Skip to content

[codex] Prioritize web port output#3

Merged
michaelmwu merged 2 commits into
mainfrom
michaelmwu/worktree-web-ports
Jun 4, 2026
Merged

[codex] Prioritize web port output#3
michaelmwu merged 2 commits into
mainfrom
michaelmwu/worktree-web-ports

Conversation

@michaelmwu

@michaelmwu michaelmwu commented Jun 4, 2026

Copy link
Copy Markdown
Member

Summary

  • Print WEB_URL first from worktree port helpers so URL scanners see the web surface before API or infrastructure URLs.
  • Update the root dev script to print the full assigned worktree port block at startup before service logs.
  • Bring the MJS and Python helper variants into alignment with reserved-block handling, browser-safe ports, and concise collision errors.

Validation

  • node extras/dev-scripts/worktree-ports.mjs env
  • WORKTREE_PORT_BLOCK_START=9000 node extras/dev-scripts/worktree-ports.mjs env
  • ./scripts/worktree-ports.sh env
  • WORKTREE_PORT_BLOCK_START=9000 ./scripts/worktree-ports.sh env
  • node --check extras/dev-scripts/worktree-ports.mjs
  • sh -n scripts/worktree-ports.sh scripts/dev.sh
  • python3 -m py_compile stacks/python/scripts/worktree-ports.py
  • focused python3 behavior assertions for the Python helper
  • bun run lint
  • bun run format:check
  • git diff --check

Notes

UV_LOCKED=1 uv run pytest tests/test_worktree_ports.py could not run because the global exclude-newer setting would require updating uv.lock. ./scripts/test.sh could not run because vitest is not installed in this workspace.

Summary by CodeRabbit

  • Documentation

    • Updated quickstart and development guidance to document worktree port output order, ensuring WEB_URL appears first for orchestrators scanning startup output.
  • New Features

    • Development startup now displays assigned worktree ports in a dedicated section.
    • Port allocation logic now supports reserved port blocks and browser-safe port assignment.
  • Chores

    • Enhanced port helper scripts with improved validation and error handling for port assignment.

Copilot AI review requested due to automatic review settings June 4, 2026 01:51
@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@michaelmwu, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 45 minutes and 26 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d9e3cddd-6a92-4e1b-9918-d9435e73efc9

📥 Commits

Reviewing files that changed from the base of the PR and between e6d673d and e7654cc.

📒 Files selected for processing (4)
  • extras/dev-scripts/worktree-ports.mjs
  • scripts/worktree-ports.sh
  • stacks/python/scripts/worktree-ports.py
  • stacks/python/tests/test_worktree_ports.py
📝 Walkthrough

Walkthrough

The PR standardizes port helper output ordering across shell, Node.js, and Python implementations so that WEB_URL prints first, followed by WEB_PORT and remaining ports. This enables orchestrators to discover and open the web surface before other services. Documentation, implementation, tests, and integration are updated consistently.

Changes

Port Helper Output Ordering

Layer / File(s) Summary
Documentation and requirements
docs/development.md, README.md
Development docs specify the required output order (WEB_URL first), and README clarifies this for orchestrators scanning startup output.
Bash worktree-ports.sh implementation
scripts/worktree-ports.sh
The shell script derives WEB_URL from the web port, reorders print_env output to place WEB_URL first, and exports it alongside WEB_API_BASE_URL and OTEL_EXPORTER_OTLP_ENDPOINT.
Node.js worktree-ports.mjs refactor
extras/dev-scripts/worktree-ports.mjs
The Node.js script is refactored with reserved-block sizing constants, browser-safe port selection (skipping restricted ports), optional primary-port override, duplicate-port validation, and error handling with stderr logging and non-zero exit codes.
Python worktree-ports.py implementation
stacks/python/scripts/worktree-ports.py
The Python script reorders HASH_OFFSETS to prioritize WEB_PORT and updates env_values() to explicitly compute WEB_URL from WEB_PORT and place it first in the result map.
Python test validation
stacks/python/tests/test_worktree_ports.py
Existing assertions are reordered to check WEB_PORT before API_PORT, and a new test verifies env_values() yields WEB_URL first and computes it correctly from the port block start.
Service startup integration
scripts/dev.sh
The startup script prints assigned worktree ports from the ordered env output, adds a "Starting services" header, and updates the web status message to reference ${WEB_URL}.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 The web port hops to the front of the line,
Where orchestrators find it, so perfectly fine,
Through bash and through Python, through Node scripts we go,
All ordered the same way—a harmonious flow!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title '[codex] Prioritize web port output' clearly summarizes the main change: reordering port output to ensure WEB_URL appears first in worktree port helper output.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch michaelmwu/worktree-web-ports

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e6d673d14e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/worktree-ports.sh
POSTGRES_URL="postgresql://app:app@127.0.0.1:${POSTGRES_HOST_PORT}/app"
DATABASE_URL="$POSTGRES_URL"
REDIS_URL="redis://127.0.0.1:${REDIS_HOST_PORT}/0"
WEB_URL="http://127.0.0.1:${WEB_PORT}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recompute WEB_URL after direct port overrides

When using the documented exec form with a direct port override, such as ./scripts/worktree-ports.sh exec WEB_PORT=9999 -- ..., run_with_env calls export_env and then re-exports the override, so WEB_PORT becomes 9999 while this newly added WEB_URL still points at the generated port. Any tool or service that consumes WEB_URL in that context opens the wrong address; recompute derived URLs after overrides or derive them from the final port values. The Python helper has the same stale WEB_URL pattern.

Useful? React with 👍 / 👎.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts the worktree port helpers and dev startup output so the web surface is discovered first by tooling that scans logs for URLs, and aligns the Node/Python/Bash variants around reserved-block allocation, browser-restricted port avoidance, and clearer collision handling.

Changes:

  • Print WEB_URL first (then WEB_PORT, API_PORT, …) across the worktree port helpers and document the ordering.
  • Update scripts/dev.sh to print the full assigned worktree port block before service logs.
  • Expand the Node (MJS) helper to match the reserved-block + browser-safe behavior already present in the other variants.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
stacks/python/tests/test_worktree_ports.py Adds an assertion that env_values() returns keys with WEB_URL first.
stacks/python/scripts/worktree-ports.py Reorders/extends env_values() output to include WEB_URL first and keeps reserved-block logic aligned with other helpers.
scripts/worktree-ports.sh Adds WEB_URL, prints it first in env, and exports it for consumers.
scripts/dev.sh Prints the full worktree-ports.sh env block up front; uses WEB_URL in the startup banner.
README.md Documents that the helper prints WEB_URL first for URL-scanning tools.
extras/dev-scripts/worktree-ports.mjs Aligns Node helper with reserved block handling, browser-restricted ports, and clearer error reporting; emits WEB_URL first.
docs/development.md Documents the expected output ordering for worktree-ports.sh env.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread stacks/python/scripts/worktree-ports.py Outdated
Comment on lines 226 to 229
@@ -228,8 +228,17 @@ def env_values(env: dict[str, str] | None = None) -> dict[str, str]:
values = ports_for_environment(env or os.environ)
postgres = values["POSTGRES_HOST_PORT"]

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@extras/dev-scripts/worktree-ports.mjs`:
- Around line 26-32: Reformat the WEB_RESTRICTED_PORTS constant so it matches
the repository's Biome formatting rules: run the project formatter (Biome) on
extras/dev-scripts/worktree-ports.mjs or specifically reformat the
WEB_RESTRICTED_PORTS array definition (the Set([...]) block) and then re-run the
linter/CI; ensure spacing, line breaks, and trailing commas follow the repo
formatter conventions so CI passes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 903e7593-6a9a-498c-9829-ed9dc13c13c0

📥 Commits

Reviewing files that changed from the base of the PR and between 8662318 and e6d673d.

📒 Files selected for processing (7)
  • README.md
  • docs/development.md
  • extras/dev-scripts/worktree-ports.mjs
  • scripts/dev.sh
  • scripts/worktree-ports.sh
  • stacks/python/scripts/worktree-ports.py
  • stacks/python/tests/test_worktree_ports.py

Comment thread extras/dev-scripts/worktree-ports.mjs
@michaelmwu michaelmwu merged commit bc37e91 into main Jun 4, 2026
6 checks passed
@michaelmwu michaelmwu deleted the michaelmwu/worktree-web-ports branch June 4, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants